<template>
  <div class="myPage">
   <div class='card'>
      <div class="blue"  margin-buttom='20px'>生成计划</div>
      <form-list-3 :planTag="tag1" :keys="keys1" @add="add" ref="formList3" :showEd="!('see'===this.$route.query.state)"></form-list-3>
    </div>
    <div style="justify-content: space-between;border-radius: 5px 5px 5px 5px;
  border: 1px solid #D7D7D7;margin-top: 20px;">
      <el-menu :default-active="active" class="el-menu-demo menu" popper-class="myMenu"
               mode="horizontal" @select="handleSelect">
        <el-menu-item index="1" :disabled="tableData2.length!==0">散货</el-menu-item>
        <el-menu-item index="2" :disabled="tableData1.length!==0">件杂货</el-menu-item>
      </el-menu>
      <!-- <div>
        style="width: 200px;margin: 0;padding: 0"
        <el-button type="text" @click="link" style="line-height: 10px">
          <span class="iconfont icon-ai207"></span>
          返回
        </el-button>
      </div> -->
 
    <hr style="height: 1px;border: 0;background: #eee;margin-bottom: 10px"/>
<!--    <div>{{tableData}}</div>-->
    <!-- <search-form ref="search" @delTag="delBat" :keys="workKey" @add="add" @planTag="planTag"></search-form>  @selection-change="handleSelectionchangeS"-->
    <el-table
        :data="tableData"
        ref="table"
        :disabled="!('see'===this.$route.query.state)"
        style="width: 100%">
      <!-- <el-table-column
          :row-key="getRowKeys"
          :reserve-selection="true"
          type="selection"
          width="55">
      </el-table-column> -->
      <el-table-column
          prop="date"
          label="序号"
          width="150">
        <template slot-scope="scope">
          <span>{{scope.$index+1}}</span>
        </template>
      </el-table-column>
      <el-table-column
          prop="planBulkGoods.gname"
          label="货物名称"
          width="120">
      </el-table-column>
      <el-table-column
          label="委托重量（吨）"
          width="220" v-if="out">
        <template slot-scope="scope">
          <el-input-number size="small" controls-position="right" :disabled="quSee&&'false'!==quSee" @input="changeS(scope.row)" v-model="tableData[scope.$index].
              planBulkGoods.planContainerGoods.gcentwg" :min="0"></el-input-number>
        </template>
      </el-table-column>
      <el-table-column
          label="委托数量"
          width="220" v-if="out">
        <template slot-scope="scope">
          <el-input-number size="small" controls-position="right" :disabled="quSee&&'false'!==quSee" @input="changeS(scope.row)" v-model="tableData[scope.$index].
            planBulkGoods.planContainerGoods.gcentpks"  :min="0"></el-input-number>
        </template>
      </el-table-column>
      <el-table-column
          prop="name"
          label="货物形态"
          width="120">
        <template slot-scope="scope">
          <span v-if="'HWXT_JZH'===scope.row.planBulkGoods.morphology">件杂货</span>
          <span v-if="'HWXT_SZH'===scope.row.planBulkGoods.morphology">散货</span>
        </template>
      </el-table-column>
      <el-table-column
          prop="planBulkGoods.gtypecd"
          label="货种"
          width="120">
        <template slot-scope="scope">
          <span v-for="item,index in goodsType" :key="index">
            <span v-if="scope.row.planBulkGoods.gtypecd===item.type">
            {{item.name}}</span></span>
        </template>
      </el-table-column>

<!--      <el-table-column
          v-if="'1' === active"
          prop="planBulkGoods.spec1"
          label="规格型号1"
          width="120">
      </el-table-column>-->
      <el-table-column
          v-if="'2' === active"
          prop="planBulkGoods.markerno"
          label="唛头"
          width="120">
      </el-table-column>
      <el-table-column
          prop="planBulkGoods.planContainerGoods.gcentwg"
          label="委托重量（吨）"
          width="120" v-if="!out">
      </el-table-column>
      <el-table-column
          v-if="'2' === active"
          prop="planBulkGoods.gunit"
          label="计量单位"
          width="120">
      </el-table-column>
      <el-table-column
          v-if="'2' === active"
          prop="planBulkGoods.planContainerGoods.gcentpks"
          label="委托数量"
          width="120">
      </el-table-column>

      <el-table-column
          prop="planBulkGoods.goodsFrom"
          label="货物来源"
          width="120">
      </el-table-column>
      <el-table-column
          prop="planBulkGoods.goodsTo"
          label="货物流向"
          width="120">
      </el-table-column>
      <el-table-column
          prop="planBulkGoods.remark"
          label="备注"
          width="120">
          <template slot-scope="scope">
            <el-tooltip :content="scope.row.planBulkGoods.remark"
                      placement="bottom"
                      popper-class="testtooltip">
                      <span>{{ scope.row.planBulkGoods.remark | subStr(8) }}</span>
            </el-tooltip>
          </template>
      </el-table-column>
      <el-table-column
          prop="planBulkGoods.spec1"
          label="规格型号"
          width="120">
      </el-table-column>
      <!-- <el-table-column
          v-if="'2' === active"
          prop="planBulkGoods.spec2"
          label="规格型号2"
          width="120">
      </el-table-column>
      <el-table-column
          v-if="'2' === active"
          prop="planBulkGoods.spec3"
          label="规格型号3"
          width="120">
      </el-table-column> -->
      <el-table-column
          v-if="'2' === active"
          prop="planBulkGoods.origin"
          label="产地"
          width="120">
      </el-table-column>
      <el-table-column
          v-if="'2' === active"
          prop="planBulkGoods.pktype"
          label="包装类型"
          width="120">
      </el-table-column>

      <el-table-column
          fixed="right"
          label="操作"
          width="250">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row,'see')" type="text" style="color: #1955CF">查看</el-button>
          <el-button v-if="('see'!==$route.query.state)&&!('loadIn'===$route.query.path||'output'===$route.query.path)" @click="handleClick(scope.row)" type="text" style="color: #1955CF">编辑</el-button>
          <el-button v-if="('see'!==$route.query.state)&&!('loadIn'===$route.query.path||'output'===$route.query.path)" @click="del(scope)" type="text" style="color:  #eb2a2a">删除</el-button>
        </template>
      </el-table-column>
      <!-- <template slot="empty">
        <div style="width: 500px;height: 200px;line-height: 500px">暂无数据</div>
      </template> -->
    </el-table>
  </div>
    <el-dialog
        :title="title"
        :before-close="cancelForm"
        :visible.sync="dialog"
        custom-class="demo-drawer"
        width="800px"
        ref="drawer">
      <div class="demo-drawer__content" style="display: flex;flex-wrap: wrap;
      flex-direction: column;align-content: space-around">
        <form-list :showEd="!see" @cal="dialog=false" @sub="submit" ref="formList" :keys="keys"></form-list>
      </div>
    </el-dialog>
    <!-- <div style="display: flex;flex-direction: row-reverse;margin-top: 10px">
      <el-pagination
          background
          :total="5"
          layout="prev, pager, next">
      </el-pagination>
    </div> -->
    <div style="display: flex;justify-content: center;">
      <el-button :loading="loading" @click="submitDate" type="primary" style="margin-top:20px;background: #0F47B8;" v-if="'see'!==$route.query.state">提交申请</el-button>
    </div>
    <newLeftMenu2 ref="newLeftMenu2" v-show="false"></newLeftMenu2>
  </div>
</template>

<script>
import searchForm from "@/views/businessProcessing/module/searchForm";
import formList from "@/views/businessProcessing/goodContent/moudel/formList";
import formList3 from "@/views/businessProcessing/goodContent/moudel/formList3";
import newLeftMenu2 from '@/components/newLeftMenu2.vue'
export default {
  name: "bulkCargo",
  components:{
    searchForm,
    formList3,
    formList,
    newLeftMenu2
  },
  data() {
    return {
      keys1:['mt','myl','tdh','khlx','cblx','jsfs','kssj','lx','shf','bt','hr'],
      quSee:false,
      goodsType:[],
      ships:[],
      out:false,
      page:0,
      pageSize:10,
      workKey:[],
      keys:['form1'],
      active:'1',
      title:'新增',
      loading:false,
      formLabelWidth:200,
      form:{},
      dialog:false,
      tableData: [],
      tableData1:[],
      tableData2:[],
      selection:[],
      tag:'',
      tag1:'',
      formList:{},
      see:false,
      myTable:[],
      loading:false,
    };
  },
  mounted() {
    this.getInfo()
    this.setTag()
    this.$refs.formList3.getDateList()
  },
  watch:{
    '$route'(){
      
      //this.getInfo()
      //this.setTag()
    }
  },
  destroyed() {
    //localStorage.setItem('myDate','')
  },
  //通过路由规则，离开该组件时被调用
beforeRouteLeave (to, from, next) {
      // console.log('About--beforeRouteLeave',to,from)
      let nowJsonData = JSON.stringify(this.$refs.formList3.form)
      let oldFormJson = JSON.stringify(this.$refs.formList3.oriForm)
      // console.log(nowJsonData,oldFormJson) //;
      if(nowJsonData!=oldFormJson && to.query.name!='jGoods'  && this.quSee){
        this.$nextTick(()=>{
          this.$confirm('存在未提交信息，确认关闭？',{
            closeOnHashChange:false,
            closeOnClickModal:false,
            distinguishCancelAndClose:true,
            closeOnPressEscape:false,
            confirmButtonText: '确定',
            cancelButtonText: '取消',
          })
                .then(_ => {
                  console.log('这边有问题',this.$route.path);
                  this.$store.commit('setActiveMenuPath',next.fullPath)
                  next()
                })
                .catch(_ => {
                  this.$store.commit('setActiveMenuPath',from.fullPath)
                  this.$nextTick(()=>{
                    let path = {
                      index: from.fullPath,
                    }
                    // this.$refs.newLeftMenu2.getActivePath(path) 
                    this.$refs.newLeftMenu2.getPath(from.fullPath)
                    this.$refs.newLeftMenu2.linkTab(from.fullPath)
                  })
                  // this.$refs.newLeftMenu2.linkTab(from.fullPath)
                  // console.log('path: ' + from.fullPath,this.$route.path);
                });
        })
      }else{
        next()
      }
  },
  methods:{
    delBat(){

      let s = this.selection
      if(0===s.length){
        this.$message.error('请先选择货物！')
        return;
      }
      //console.log(s)
      //return
      //console.log(e.$index)
      let that=this

      this.$confirm('确定要删除货物吗？')
          .then(_ => {
            if('1' === that.active){
              that.tableData.forEach((item,index)=>{
                s.forEach(item1=>{
                  if(JSON.stringify(item1) === JSON.stringify(item)){
                    that.tableData.splice(index,1)
                    that.tableData=that.tableData1
                  }
                })
              })
            }
            if('2' === that.active){
              that.tableData2.forEach((item,index)=>{
                s.forEach(item1=>{
                  if(JSON.stringify(item1) === JSON.stringify(item)){
                    that.tableData2.splice(index,1)
                    that.tableData=that.tableData2
                  }
                })
              })
            }
            this.$refs.table.clearSelection()
            this.selection=[]
            this.$message.success('批量删除成功！')
          })
          .catch(_ => {});

    },
    changeS(e){
      /*console.log(9999999)
      console.log(e)*/
      this.$nextTick(() => {
        if(undefined!==e.planBulkGoods.planContainerGoods.gcentwg&&
            0!==e.planBulkGoods.planContainerGoods.gcentwg&&
            0!==e.planBulkGoods.planContainerGoods.gcentpks){
          //这里把数据重新赋值一下，不然就会出现bug，从第一页翻到第二页可以保留，在回到第一页选中的就没了
          this.$refs.table.toggleRowSelection(e, true);
          //this.$forceUpdate()
        }else{
          this.$refs.table.toggleRowSelection(e, false);
        }
      });
    },
    getGoods(){
      this.out = true
      this.tableData=[]
      this.$api.tosGetGoods({
        "planTag": this.tag,
        "termCode": "HX"
      }).then(res=>{
        res.data.forEach(item=>{
          let c={planBulkGoods:item}
          c.planBulkGoods.planContainerGoods={}
          c.planBulkGoods.planContainerGoods={
            gcentpks:0,//item.gtpks,
            gcentpksMax:item.gtpks,
            gcentwg:0,//item.gtwg
            gcentwgMax:item.gtwg
          }
          this.tableData.push(c)
        })
        // console.log()
        this.tableData2.forEach(item=>{
          this.myTable.push(item)
        })
        //this.myTable=Object.assign(this.myTable,this.tableData2)
        if(0!==this.myTable.length){
          this.tableData.forEach(item=>{
            this.myTable.forEach(item1=>{
              if(item.planBulkGoods.bulkGId===item1.planBulkGoods.bulkGId){
                //console.log(1111)
                item.planBulkGoods.planContainerGoods=item1.planBulkGoods.planContainerGoods
              }else{
                //console.log(22222)
              }
            })
          })
        }
        this.$forceUpdate()
      }).catch()
    },
    async setTag(){
      let tag = null
      let url1=this.$route.query.type
      let url=this.$route.name
      //console.log(this.$route.query)
      this.tag=url1
      console.log(url)
      if(undefined===this.tag){
        if('jUnloadLift'===url){
          this.tag='XCZT_G'
          this.tag1='XCZT'
          this.keys1.push('cddw')
          this.keys1.push('hmh')
        }
        if('jUnloadIn'===url){
          this.tag='XCRK_G'
          this.tag1='XCRK'
          this.keys1.push('hmh')
        }
        if('jLoadLift'===url){
          this.tag='ZCZZ_G'
          this.tag1='ZCZZ'
          this.keys1.push('cddw')
          this.keys1.push('hmh')
        }
        if('jLoadIn'===url){
          this.tag='ZCCK_G'
          this.tag1='ZCCK'
          this.keys1.push('hmh')
        }
        if('jImport'===url){
          this.tag='JH_G'
          this.tag1='JH'
          this.keys1.push('cddw')
          this.keys1.push('hmh1')
        }
        if('jOutput'===url){
          this.tag='TH_G'
          this.tag1='TH'
          this.keys1.push('cddw')
          this.keys1.push('hmh1')
        }
      }
      this.$api.getGoodsType().then(res=>{
        this.goodsType=res.data
      }).catch()
      if('see'===this.$route.query.state){
        this.quSee=false
      }else{
        this.quSee=true
      }
      //''!==localStorage.getItem('myDate')
      if(undefined!==this.$route.query.id){
        let c=await this.$api.detailGoods({
          id:this.$route.query.id
        }).then(res=>{
          //console.log(res.data)
          return res.data
          
        }).catch(res=>{
          return null
        })
        
        //let c=JSON.parse(localStorage.getItem('myDate'))
        /*console.log('ppppppp')
        console.log(c)*/
        let that=this
        
        this.$nextTick(() => {
          that.$refs.formList3.getVel1()
          this.$refs.formList3.$refs.myUpload.file=JSON.parse(JSON.stringify(c.planAttachmentList))
        })

        c.planBulkGoods.forEach((item,index)=>{
          this.tableData.push({
            planBulkGoods:item,
            plansExt:c.plansExt,
            edit:1
          })
          //this.$refs.table.toggleRowSelection(this.tableData[index], true);
          /*this.$refs.table.toggleRowSelection(item, true);
          this.$forceUpdate()*/
        })
        /*console.log(9999999)
        console.log(this.tableData[0])
        console.log(this.tableData.length>0&&null!==this.tableData[0].planBulkGoods)*/

        if(this.tableData.length>0&&null!==this.tableData[0].planBulkGoods){
          this.tableData.forEach(item=>{
            console.log(666)
            console.log(item.planBulkGoods.morphology)
            if('HWXT_JZH'===item.planBulkGoods.morphology){
              this.tableData2.push(item)
              this.active='2'
              //console.log(3333)
            }else{
              this.tableData1.push(item)
              this.active='1'
              //console.log(2222222)
            }
            
          })
          if(this.active==='1'){
            this.tableData= JSON.parse(JSON.stringify(this.tableData1))
          }else{
            this.tableData= JSON.parse(JSON.stringify(this.tableData2))
          }
          console.log(808080)
          console.log(this.tableData)
          // console.log(this.t)
          // this.active='1'
        }else{

        }

        try {
          this.$refs.formList3.form=c
        }catch (e) {
          console.log(e)
        }
        if('loadIn'===this.$route.query.path||'output'===this.$route.query.path) {
          this.myTable = JSON.parse(JSON.stringify(this.tableData))
          this.getGoods()
        }
        //console.log(c)
      }else if('loadIn'===this.$route.query.path||'output'===this.$route.query.path){
        this.getGoods()
      }
    },
    getInfo(){
      console.log(11111)
      console.log(this.$route.query)
      this.quSee=this.$route.query.state
      if(undefined===this.$route.query.state){
        console.log(88888)
        localStorage.setItem('myDate','')
      }
      this.see = this.quSee || 'true' === this.quSee;
      console.log(this.see)
      if('loadIn'===this.$route.query.path||'output'===this.$route.query.path){
        this.workKey=['work','shipName','comType','num','out','del','add','import']
      }else{
        this.workKey=['work','shipName','comType','num','ship1','out','del','add','import','hr']
      }
      if(undefined === this.$route.query.id){
         this.$api.getCustomerInfo().then(res=>{
        this.$set(this.$refs.formList3.form,'customerPhone',res.data.tel)
        this.$set(this.$refs.formList3.oriForm,'customerPhone',res.data.tel)
          console.log(this.$refs.formList3.form)
        }).catch
      }
     
    },
    submitDate(){
        this.$refs.formList3.$refs.form.validate((valid) => {
          if (valid) {
            this.submitDate1()
            //alert('submit!');
            return true
          } else {
            this.$message.error('请填写必填项!')
            console.log('error submit!!');
            // this.loading=false
            return false;
          }
        });
    },
    submitDate1(){
        if(0===this.tableData.length){
          this.$message.error('请选择数据！')
          this.dialog=false
          this.loading=false
          return
        }
        // if(undefined===this.$refs.formList3.form.termCode){
        //   this.loading=false
        //   this.$message.error('请选择作业码头！')
        //   return;
        // }
        // if(undefined===this.$refs.formList3.form.vslCd){
        //   this.loading=false
        //   this.$message.error('请选择船名航次！')
        //   return;
        // }
        let that=this
        let c= JSON.parse(JSON.stringify(this.$refs.formList3.form))
        c.planTag=this.tag
        //c.createUser='admin'
        // c.cstCstmcd=this.$refs.search.form.cstCstmcd
        // c.vslCd=this.$refs.search.form.vslCd
        // c.termCode=this.$refs.search.form.termCode//this.keys.includes('form1')?'HX':'LTG'
        c.opprc='ZYLX_CC'
        let k=JSON.parse(JSON.stringify(this.tableData))
        let goods=[]
        k.forEach(item=>{
          goods.push(item.planBulkGoods)
        })
        this.$set(c,'planBulkGoods',goods)
        console.log(c)
        console.log('kkkk')
        console.log(this.tag)
        let type=that.tag
        console.log(c.id)
        if(null===c.id||undefined===c.id){
          type='_Add'
        }else{
          type='_Edit'
        }
        this.loading=true
        this.$api.shipE(c,this.tag+type).then(res=>{
          if(200===res.code){
            this.dialog=false
            let that= this
            this.$message.success({message:'_Add'===type?
                  '新增计划成功！':'编辑计划成功！',onClose(){
                that.selection=[]
                that.tableData=[]
                that.$refs.formList3.form={}
                localStorage.setItem('myDate','')
                that.link()
              }
            })
          }else{
            this.loading=false
            //this.$message.error(res.message)
          }
        }).catch(err=>{
          this.loading=false
          //this.$message.error(err.message)
        })
    },
    submit(){
        this.$refs['formList'].$refs.form.validate((valid) => {
          if (valid) {
            this.submit1()
            //alert('submit!');
            return true
          } else {
            this.$message.error('请填写必填项!')
            console.log('error submit!!');
            return false;
          }
        });
    },
    submit1(){
      if(this.keys.includes('form1')){
        //console.log(66555237496)
        console.log(this.$refs.formList.form)
        console.log(8888888)
        console.log(this.tableData1)
        console.log(this.tableData)
        let c=JSON.parse(JSON.stringify(this.$refs.formList.form))
        if('新增'===this.title&&1!==c.edit){
          this.tableData1.push(c)
        }
        this.tableData=this.tableData1
        //this.$refs.table.toggleRowSelection(c, true);
        this.dialog=false
      }
      if(this.keys.includes('form3')){
        //console.log(66555237496)
        console.log(this.$refs.formList.form)
        let c=JSON.parse(JSON.stringify(this.$refs.formList.form))
        if('新增'===this.title&&1!==c.edit){
          this.tableData2.push(c)
        }
        /*this.tableData2.push(c)*/
        this.tableData=this.tableData2
        this.dialog=false
      }
      if(this.keys.includes('form2')){
        /*console.log(this.selection.length)
        console.log(this.$refs.formList.form)*/
        let that=this
        let c= JSON.parse(JSON.stringify(this.$refs.formList.form))
        c.planTag=this.tag
        //c.createUser='admin'
        c.cstCstmcd=this.$refs.search.form.cstCstmcd
        c.vslCd=this.$refs.search.form.vslCd
        c.termCode=this.$refs.search.form.termCode//this.keys.includes('form1')?'HX':'LTG'
        c.opprc='ZYLX_CC'
        let k=JSON.parse(JSON.stringify(this.selection))
        let goods=[]
        k.forEach(item=>{
          goods.push(item.planBulkGoods)
        })
        this.$set(c,'planBulkGoods',goods)
        console.log(c)
        console.log('kkkk')
        console.log(this.tag)
        let type=that.tag
        console.log(c.id)
        if(null===c.id||undefined===c.id){
          type='_Add'
        }else{
          type='_Edit'
        }
        this.$api.shipE(c,this.tag+type).then(res=>{
          if(200===res.code){
            this.dialog=false
            let that= this
            this.$message.success({message:'_Add'===type?
                  '新增计划成功！':'编辑计划成功！',onClose(){
                that.link()
              }
            })
          }else{
            //this.$message.error(res.message)
          }
        }).catch(err=>{
          //this.$message.error(err.message)
        })
      }
      /*console.log(this.$refs.formList.form)
      this.$api.xAdd(this.$refs.formList.form).then().catch()*/
    },
    planTag(){
      if(0===this.selection.length){
        this.$message.error('请选择数据！')
        this.dialog=false
        return
      }
      if(undefined===this.$refs.search.form.termCode){
        this.$message.error('请选择作业码头！')
        return;
      }
      if(undefined===this.$refs.search.form.vslCd){
        this.$message.error('请选择港口！')
        return;
      }

      if(!this.quSee||'false'===this.quSee){
        this.see=false
      }else{
        this.see=true
      }
      this.keys=['form2']
      this.title='生成计划'
      this.dialog=true
      this.$nextTick(res=>{
        //this.$refs.formList.form.plansExt.createUser='admin'
        console.log(99999)
        /*let e=localStorage.getItem("userInfo");
        console.log(e)
        let b=this.$store;
        console.log(b)*/
        /*let e=localStorage.getItem("userInfo");
        if(null===e){
          this.$refs.formList.form.plansExt.createUser=''//'admin'
        }else{
          this.$refs.formList.form.plansExt.createUser=JSON.parse(e).name
        }*/
        if(undefined!==this.formList.id&&null!==this.formList.id){
          this.$refs.formList.form=this.formList
        }else{
          this.$refs.formList.form={
            plansExt:{
              createUser:'',
              recipient:'',
              billNo:'',
              moveTo:''
            },
            planBulkGoods:{
              receiverName:'',
              morphology:this.keys.includes('form1')?'HWXT_SZH':'HWXT_JZH',
              gtypecd:'',
              planContainerGoods:{},
              gname:'',
              gunit:'',
            },
            planContainerGoods:{
              gcentwg:'',
              gcentpks:''
            },
            isCheck:-1,
            billno:1
          }
        }
        this.$forceUpdate()
      })
    },
    add(v){
      this.see=false
      console.log(7777777)
      console.log(v)
      if(('1'===v&&this.tableData2.length>0)||('2'===v&&this.tableData1.length>0)){
        this.$message.error('不可以同时添加件散货和件杂货！')
        return
      }
      if('1'===v){
        this.active='1'
      }
      if('2'===v){
        this.active='2'
      }
      if('1'===this.active){
        this.keys=['form1']
      }
      if('2'===this.active){
        this.keys=['form3']
      }

      //this.keys=['form1']
      this.title='新增'
      this.dialog=true
      this.$nextTick(res=>{
        /*this.$refs.formList.form={
          default: () => []
        }*/
        this.$refs.formList.getGoods()
        this.$refs.formList.form={
          plansExt:{
            createUser:'',
            recipient:'',
            billNo:''
          },
          planBulkGoods:{
            receiverName:'',
            morphology:this.keys.includes('form1')?'HWXT_SZH':'HWXT_JZH',
            gtypecd:'',
            planContainerGoods:{},
            gname:'',
            gunit:'',
          },
          planContainerGoods:{
            gcentwg:'',
            gcentpks:''
          },
          isCheck:-1,
          billno:1
        }

      })
    },
    handleSelect(e){
      console.log(e)
      this.active=e
      console.log(e)
      if('1'===e){
        if(this.tableData2.length===0){
          console.log(777)
          this.tableData=this.tableData1
          this.keys=['form1']
        }else{
          this.$message.error('请先清空件杂货！')
          this.active='2'
          return
        } 
      }
      if('2'===e){
        if(this.tableData1.length===0){
          console.log(888)
          this.tableData=this.tableData2
          this.keys=['form3']
        }else{
          this.$message.error('请先清空散货！')
          this.active='1'
        }
      }
      //console.log(this.active)
    },
    link(){
      this.$router.push({
        query:{
          name:'jGoods'
        },
        name:'success'
      })
    },
    cancelForm() {
      //this.keys=['form1']
      this.loading = false;
      this.dialog = false;
      /*this.$refs.formList.form={
        default: () => []
      }*/
      //clearTimeout(this.timer);
    },
    del(e){
      console.log(e.$index)
      let that=this
      this.$confirm('确定要删除货物吗？')
          .then(_ => {
            if('1' === that.active){
              that.tableData1.splice(e.$index,1)
              that.tableData=that.tableData1
            }
            if('2' === that.active){
              that.tableData2.splice(e.$index,1)
              that.tableData=that.tableData2
            }
            this.$refs.table.clearSelection()
            this.selection=[]
            this.$message.success('删除成功！')
          })
          .catch(_ => {});

    },
    handleClick(row,e) {
      if('1'===this.active){
        this.keys=['form1']
      }
      if('2'===this.active){
        this.keys=['form3']
      }
      //this.keys=['form1']
      console.log(row);
      row.edit=1
      //console.log('ppppppp')
      if('see'!==e){
        this.title='编辑'
        this.see=false
      }else{
        this.title='查看'
        this.see=true
      }
      this.dialog=true
      this.$nextTick(res=>{
        this.$refs.formList.getGoods()
        this.$refs.formList.form=row//JSON.parse(JSON.stringify(row))
      })
    },
    handleSelectionchangeS(val) {
      this.selection = val;
      //this.$refs.table.toggleRowSelection(val, true);
    },
    getRowKeys(row) {
      return row.id
    },
  },
}
</script>

<style scoped lang="less">
/deep/ .el-input.is-disabled .el-input__inner {
  color: #666

}
/deep/ .el-textarea.is-disabled .el-textarea__inner {
  color: #666
}
.el-menu-item {
  height: 39px;
  line-height: 39px;
}
.el-menu{
  border: none;
  background: transparent;
}
.el-menu::after{
  border: none;
  background: transparent;
}
.myPage{
  background: #fff;
  padding: 10px 20px 20px 20px;
  border-radius: 6px;
  // height: 660px;
  // overflow: auto;
}
/deep/ .el-table__empty-block {
  justify-content: flex-start!important;
}
.card{
  border-radius: 5px 5px 5px 5px;
  opacity: 1;
  border: 1px solid #D7D7D7;
  .blue{
    height: 50px;
    background: #0F47B8;
    opacity: 1;
    line-height: 50px;
    color: #fff;
    padding-left: 30px;
  }
}
</style>
